//
//  RENavigationView.m
//  ReelEp
//
//  Created by 孙强 on 2024/7/14.
//  Copyright © 2024 RE. All rights reserved.
//

#import "RENavigationView.h"

@implementation RENavigationView


- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView{
    
    self.backgroundColor = UIColor.clearColor;
        
    UIView * leftView = [[UIView alloc] initWithFrame:CGRectMake(0, StatusHeight, 60, 44)];
    UIImageView * imageview = [[UIImageView alloc] initWithFrame:CGRectMake(16, 4, 20, 36)];
    imageview.image = readImageFromImageName(@"iconBack");
    imageview.userInteractionEnabled = YES;
    [leftView addSubview:imageview];
    UITapGestureRecognizer * tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backClick)];
    [leftView addGestureRecognizer:tap1];
    [self addSubview:leftView];
    _backImageView = imageview;
    _leftView = leftView;

    _titleLabel = [[UILabel alloc] init];
    [self addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.bottom.equalTo(self);
        make.top.equalTo(StatusHeight);
    }];
    _titleLabel.textColor = UIColor.blackColor;
    _titleLabel.font = [UIFont boldSystemFontOfSize:18];
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.centerY.equalTo(_titleLabel);
        make.height.mas_equalTo(44);
//        make.width.equalTo(120);
    }];
    [button setTitleColor:COLOR_TITLE forState:UIControlStateNormal];
    button.titleLabel.font = FONT(14);
    _rightButton = button;
    
}
- (void)setImageTitle:(NSString *)imageTitle{
    _imageTitle = imageTitle;
    _backImageView.image = readImageFromImageName(imageTitle);
    self.backgroundColor = UIColor.whiteColor;
   _titleLabel.textColor = MainTitleColor;
}
- (void)setTitle:(NSString *)title{
    _title = title;
    _titleLabel.text = title;
    
}
- (void)backClick{
    if (self.backBlock) {
        self.backBlock();
    }
    
}
-(void)setButtonImageTitle:(NSString *)buttonImageTitle{
    _buttonImageTitle = buttonImageTitle;
    UIImage *image = [UIImage imageNamed:buttonImageTitle];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [_rightButton setImage:image forState:UIControlStateNormal];
    [_rightButton addTarget:self action:@selector(actionButton:) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void)setButtonTitle:(NSString *)buttonTitle{
    _buttonTitle = buttonTitle;
    [_rightButton setTitle:buttonTitle forState:UIControlStateNormal];
    [_rightButton addTarget:self action:@selector(actionButton:) forControlEvents:UIControlEventTouchUpInside];

}
- (void)actionButton:(UIButton *)button{
    
    if (self.doneBlock) {
        self.doneBlock(button);
    }
    
}

-(void)setTitleColorType:(NSInteger)titleColorType{
    _titleColorType = titleColorType;
    switch (titleColorType) {
        case 1:
            //白色
            _titleLabel.textColor = COLOR_MAIN;
            
            break;
            
        default:
            break;
    }
    
}
-(void)setRightTitleColor:(UIColor *)rightTitleColor{
    _rightTitleColor = rightTitleColor;
    
    [_rightButton setTitleColor:rightTitleColor forState:UIControlStateNormal];

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
